package com.utils;

import java.util.Date;

/**
 * 倒数读秒
 * <p>
 * Created by zhongl on 16/6/21.
 */
public class CountDown implements Runnable {

    //测试入口
//    public static void main(String[] args) {
//        Thread thread = new Thread(new CountDown());
//        thread.start();
//
//    }

    @Override
    public void run() {
        // 获取距离当前时间对应的毫秒数
        long endTime = System.currentTimeMillis() + 30 * 60 * 1000;

        // 获取系统当前时间
        Date now = new Date();
        // 获取当前时间点对应的毫秒数
        long currentTime = now.getTime();

        System.out.println("距离当前半小时时间:" + endTime);
        System.out.println("当前时间:" + currentTime);

        // 计算两个时间点相差的秒数
        long seconds = (endTime - currentTime) / 1000;

        while (seconds != 0) {
            System.out.println("还剩下: " + seconds + " s");
            seconds--;

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}